/*
 * This is the listerner for the disconnect button
 */
package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JTextField;

/**
 *
 * @author Nana
 */
public class DisconnectListener implements ActionListener {

    private JTextField txtfield;
    private ChatGUI gui;
    private JList connectedUsers;
    private JButton connect;
    private JButton disconnect;
    private JButton send;
    private JButton chooseFile;

    /**
     * The constructor of the listener
     *
     * @param txtfield The field with the usernaae
     * @param gui The chat gui
     * @param connectedUsers The list of connected users
     * @param disconnect The disconnec button
     * @param connect The connect button
     * @param send The send button
     * @param chooseFile The choose file button
     */
    public DisconnectListener(JTextField txtfield, ChatGUI gui, JList connectedUsers, JButton disconnect, JButton connect, JButton send, JButton chooseFile) {
        this.txtfield = txtfield;
        this.gui = gui;
        this.connectedUsers = connectedUsers;
        this.connect = connect;
        this.disconnect = disconnect;
        this.send = send;
        this.chooseFile = chooseFile;
    }

    /**
     * The action to perform when clicking on the disconnect button
     *
     * @param e The action event
     */
    @Override
    public void actionPerformed(ActionEvent e) {
        gui.Disconnect(txtfield.getText());
        txtfield.setEnabled(true);
        connectedUsers.clearSelection();
        this.chooseFile.setEnabled(false);
        this.disconnect.setEnabled(false);
        this.send.setEnabled(false);
        this.connect.setEnabled(true);
        gui.emptyConnectedUserlist();
        System.out.println("Clicked on Disconnect");
    }

}
